package com.gill.touka.mq;

import com.alibaba.fastjson.JSON;
import com.gill.touka.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class StreamConsumer {

    @Autowired
    private UserService userService;

    @StreamListener(Sink.INPUT)
    public void receive(String msg){
        log.info("从RocketMQ获取到消息，正在为share审核通过的用户添加积分，并记录日志");
        AddBonusMsg message = JSON.parseObject(msg, AddBonusMsg.class);
        userService.addBonus(message);
    }
}
